package de.rs.espresso.algorithms;

import de.rs.espresso.covers.DefaultCover;
import de.rs.espresso.interfaces.IAlgorithm;
import de.rs.espresso.interfaces.ICover;
import de.rs.espresso.interfaces.ICube;
import de.rs.espresso.interfaces.IGlobalInformation;

public class LastGasp implements IAlgorithm {

	
	private IGlobalInformation info;


	public LastGasp(IGlobalInformation info) {
		this.info = info;
	}
	
	@Override
	public ICover compute(ICover onSet, ICover offSet, ICover dcSet) {
		
		
		ICover preGSet = new Reduce(info).compute(onSet, offSet, dcSet);
		
		ICover gSet = new DefaultCover(info);
		
		for(ICube preGCube : preGSet) {
			if(!onSet.contains(preGCube)) {
				gSet.add(preGCube);
			}
		}
		
		ICover preHSet = new Expand(info).compute(gSet, offSet, dcSet);
		
		
		for(ICube preHCube : preHSet) {
			for(ICube preGCube : preGSet) {
				
				if(preHCube.covers(preGCube))
					onSet.add(preHCube);
			}
		}
		
		onSet = new Irredundant(info).compute(onSet, offSet, dcSet);		
		
		return onSet;
	}

}
